package com.dwxt.cdms.applets;

import com.alibaba.fastjson.JSONObject;
import com.dwxt.cdms.service.MinAPPService;
import com.dwxt.common.base.BaseResult;
import com.dwxt.common.util.OkHttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RequestMapping("/cdms/small")
@RestController
public class MinAPPController {

    @Autowired
    private MinAPPService minAPPService;

    /**
     * 微信用户返回openid
     *
     * @param code
     * @return
     */
    @RequestMapping("/getOpenId")
    public BaseResult getOpenId(String code) {
        String url = "https://api.weixin.qq.com/sns/jscode2session?appid=wx9ec6e8104eebfca5&secret" +
                "=ec2f5de385658502650f27e2f09dc503&js_code=" + code + "&grant_type=authorization_code";
        String s = OkHttpUtils.synGet(url, null);
        JSONObject result = JSONObject.parseObject(s);
        return BaseResult.ok(result);
    }


    /**
     * @Description: 电视端获取小程序二维码和唯一字符串
     * @Param [request, response]
     * @Return com.dwxt.common.base.BaseResult
     * @Author chendq
     * @Date 2021/12/12
     **/
    @RequestMapping(value = "/getQrCode")
    public BaseResult getQrCode() throws IOException {
        return minAPPService.getQrCode();
    }


    @RequestMapping(value = "/allowLogin")
    public BaseResult allowLogin(String scene,String phone) throws IOException {
        return minAPPService.allowLogin(scene,phone);
    }
}
